# -*- coding: utf-8 -*-
from legendaryPowerClientScript.util import apiUtil
from templateScript import templateClientSystem

class ListenerDemo:
    """
    此类实现了一个简单的监听功能：当玩家切换手中物品时，在聊天栏打印其物品名
    """
    def __init__(self):
        #事件列表：https://mc.163.com/dev/mcmanual/mc-dev/mcdocs/1-ModAPI/%E4%BA%8B%E4%BB%B6/%E4%BA%8B%E4%BB%B6%E7%B4%A2%E5%BC%95%E8%A1%A8.html?catalog=1
        templateClientSystem.mainSys.RegisterEventClientUI("OnCarriedNewItemChangedClientEvent", self, self.onItemSwapped)

    def onItemSwapped(self, event):
        #关于event的内容： https://mc.163.com/dev/mcmanual/mc-dev/mcdocs/1-ModAPI/%E4%BA%8B%E4%BB%B6/%E7%89%A9%E5%93%81.html?key=OnCarriedNewItemChangedClientEvent&docindex=1&type=0
        print "OnCarriedNewItemChangedClientEvent", event
        desc = apiUtil.formatVanillaDesc(event)
        if desc:
            apiUtil.sendChatMessage("切换到了物品：%s" % (desc[0]))